package org.dromara.nursing.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
// import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.nursing.domain.vo.MsOccupancyStatisticsVo;
import org.dromara.nursing.domain.bo.MsOccupancyStatisticsBo;
import org.dromara.nursing.service.IMsOccupancyStatisticsService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 入住率统计
 *
 * @author Lion Li
 * @date 2025-04-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nursing/occupancyStatistics")
public class MsOccupancyStatisticsController extends BaseController {

    private final IMsOccupancyStatisticsService msOccupancyStatisticsService;

    /**
     * 查询入住率统计列表
     */
    // @SaCheckPermission("nursing:occupancyStatistics:list")
    @GetMapping("/list")
    public TableDataInfo<MsOccupancyStatisticsVo> list(MsOccupancyStatisticsBo bo, PageQuery pageQuery) {
        return msOccupancyStatisticsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出入住率统计列表
     */
    // @SaCheckPermission("nursing:occupancyStatistics:export")
    @Log(title = "入住率统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MsOccupancyStatisticsBo bo, HttpServletResponse response) {
        List<MsOccupancyStatisticsVo> list = msOccupancyStatisticsService.queryList(bo);
        ExcelUtil.exportExcel(list, "入住率统计", MsOccupancyStatisticsVo.class, response);
    }

    /**
     * 获取入住率统计详细信息
     *
     * @param statId 主键
     */
    // @SaCheckPermission("nursing:occupancyStatistics:query")
    @GetMapping("/{statId}")
    public R<MsOccupancyStatisticsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long statId) {
        return R.ok(msOccupancyStatisticsService.queryById(statId));
    }

    /**
     * 新增入住率统计
     */
    // @SaCheckPermission("nursing:occupancyStatistics:add")
    @Log(title = "入住率统计", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MsOccupancyStatisticsBo bo) {
        return toAjax(msOccupancyStatisticsService.insertByBo(bo));
    }

    /**
     * 修改入住率统计
     */
    // @SaCheckPermission("nursing:occupancyStatistics:edit")
    @Log(title = "入住率统计", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MsOccupancyStatisticsBo bo) {
        return toAjax(msOccupancyStatisticsService.updateByBo(bo));
    }

    /**
     * 删除入住率统计
     *
     * @param statIds 主键串
     */
    // @SaCheckPermission("nursing:occupancyStatistics:remove")
    @Log(title = "入住率统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{statIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] statIds) {
        return toAjax(msOccupancyStatisticsService.deleteWithValidByIds(List.of(statIds), true));
    }
}
